/**
 * Created by kangdaye on 16/6/5.
 */
app.controller('userListAEDialogCtr',["$scope","$rootScope","addEditModel","gridOpt","userListService", function($scope,$rootScope,addEditModel,gridOpt,userListService) {
    $scope.isAdd = addEditModel === 'add';
    $scope.getData = {
        name : '',
        username : '',
        password : '',
        enable : 'false'
    };

    if(!$scope.isAdd){
        $scope.getData = angular.copy(addEditModel);
    }

    $scope.submit = function(){
        if($scope.isAdd){
            userListService.add($scope.getData,function(){
                gridOpt.refresh();
                $scope.closeThisDialog();  //dialog 关闭
            });
            return;
        }

        userListService.update($scope.getData,function(){
            angular.extend(addEditModel,$scope.getData);
            $scope.closeThisDialog();  //dialog 关闭
        });
    }

}]);
